<?php

namespace App\Jobs\Scenic;

use App\Services\Scenic\Adapter;
use App\Services\Scenic\ScenicQueryFactory;
use App\Trip\Enums\Scenic\ScenicProvider;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class SyncScenicDetail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private string $scenicId;
    private string $provider;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(string $scenicId,$provider)
    {
        $this->scenicId = $scenicId;
        $this->provider = $provider;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws GuzzleException
     * @throws Exception
     */
    public function handle()
    {
        Log::info('景点-'.$this->scenicId . ':begin');
        $provider = (ScenicProvider::from($this->provider));
        $driver = (new ScenicQueryFactory())->findOneByProvider($provider);
        $driver->scenicToDb($this->scenicId);
        Log::info('景点-'.$this->scenicId . ':success');
        return;
    }

    public function uniqueId(): string
    {
        return $this->scenicId;
    }
}
